package com.fullmail.fragment;

import java.util.ArrayList;
import java.util.List;

import com.fullmail.R;
import com.fullmail.ReadingFullActivity;
import com.fullmail.adapter.CardListAdapter;
import com.fullmail.bean.CardBean;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class SendedFragment extends Fragment{
	private Context mContext;
	private ListView cardListView;
	private List<CardBean> list;
	private CardListAdapter clAdapter;
	private String[] names = new String[] { "杨朝来", "蒋平", "唐灿华", "马达", "赵小雪", "薛文泉", "丁建伟", "凡小芬", "文明", "文彭凤", "王丽",
			"王建华", "王梓人", "王震", "王保真", "王景亮", "王丹", "邓志勇", "邓婕", "尹会南", "叶汝红", "付伟娜", "付双红" };

	private String[] address = new String[] { "冰岛", "波兰", "丹麦", "德国", "法国", "芬兰", "荷兰", "捷克", "挪威", "瑞典", "瑞士",
			"希腊 ", "英国 ", "爱尔兰", " 安道尔", "奥地利", " 比利时", " 俄罗斯", " 梵蒂冈", " 立陶宛", " 卢森堡", "马耳他", "马其顿"};

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.fragment_home_card, container, false);
		mContext = getActivity();
		cardListView = (ListView) view.findViewById(R.id.lv_home_card);
		initData();
		setListener();
		return view;
	}

	private void setListener() {
		// TODO Auto-generated method stub
		cardListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				Intent readCardIntent=new Intent();
				readCardIntent.setClass(mContext, ReadingFullActivity.class);
				startActivity(readCardIntent);
			}
		});
	}

	private void initData() {
		list=new ArrayList<CardBean>();
		// TODO Auto-generated method stub
		for (int i = 0; i < names.length; i++) {
			CardBean cb = new CardBean();
			cb.setAddress(address[i]);
			cb.setName("习惯受重伤");
			cb.setDesc("任何时候、任何情况，只要你需要我，我立即赶来，尽我全力为你做事。");
			cb.setHeadIconUrl("");
			list.add(cb);
		}
		clAdapter=new CardListAdapter(mContext, list);
		cardListView.setAdapter(clAdapter);
	}
}
